home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / vol_200 / 293_02 / flipv.c < prev    next >
C/C++ Source or Header  |  1989-08-23  |  3KB  |  120 lines

  1. /*********************** flipv.c **************************************
  2.  
  3.       3-D Reconstruction of Medical Images
  4.  
  5.     Three Dimensional Reconstruction Of Medical
  6.     Images from Serial Slices - CT, MRI, Ultrasound
  7.  
  8.  
  9.    These programs process a set of slices images (scans) for one
  10.    patient. It outputs two sets of files containing nine predefined
  11.    views of bony surfaces. One set contains distance values and
  12.    the other gradient values.
  13.  
  14.    The distance values are used as 3-D spatial topographic surface
  15.    coordinate maps for geometrical analysis of the scanned object.
  16.  
  17.    The gradient values are used for rendering the surface maps on
  18.    CRT displays for subjective viewing where perception of small
  19.    surface details is important.
  20.  
  21.     Daniel Geist, B.S.
  22.     Michael W. Vannier, M.D.
  23.  
  24.     Mallinckrodt Institute of Radiology
  25.     Washington University School of Medicine
  26.     510 S. Kingshighway Blvd.
  27.     St. Louis, Mo. 63110
  28.  
  29.     These programs may be copied and used freely for non-commercial
  30.     purposes by developers with inclusion of this notice.
  31.  
  32.  
  33. ********************************************************************/
  34. #include <stdio.h>
  35. #include <ctype.h>
  36. unsigned char inbuf[256],outbuf[256],fnamein[30],fnameout[30];
  37. main(argc,argv)
  38. int argc;
  39. char *argv[];
  40. {int i,j,lines;
  41.  FILE *fin,*fout;
  42.   switch (argc) {
  43.        case 1:printf(" Enter fin: ");
  44.               scanf("%s",fnamein);
  45.               printf("Enter fout: ");
  46.               scanf("%s",fnameout);
  47.               printf("Enter lines: ");
  48.               scanf("%d",&lines);
  49.               break;
  50.        case 2:if(isalpha(argv[1][0])){
  51.                   strcpy(fnamein,argv[1]);
  52.                   printf("Enter lines: ");
  53.                   scanf("%d",&lines);
  54.                   change_ext(fnamein,fnameout);
  55.               }
  56.               else{
  57.                   get_lines_arg(argv[1],&lines);
  58.                    printf(" Enter fin: ");
  59.                    scanf("%s",fnamein);
  60.                    printf("Enter fout: ");
  61.                    scanf("%s",fnameout);
  62.               }
  63.               break;
  64.         case 3:strcpy(fnamein,argv[1]);
  65.                if(isalpha(argv[2][0])){
  66.                   strcpy(fnameout,argv[2]);
  67.                   printf("Enter lines: ");
  68.                   scanf("%d",&lines);
  69.               }
  70.               else{
  71.                   get_lines_arg(argv[2],&lines);
  72.                   change_ext(fnamein,fnameout);
  73.               }
  74.               break;
  75.         default:strcpy(fnamein,argv[1]);
  76.               strcpy(fnameout,argv[2]);
  77.               get_lines_arg(argv[3],&lines);
  78.   } 
  79.   fin=fopen(fnamein,"rb");
  80.   fout=fopen(fnameout,"wb");
  81.   for(i=lines-1;i>=0;i--){
  82.       fread(inbuf,1,256,fin);
  83.       for(j=0;j<256;j++) outbuf[j]=inbuf[255-j];
  84.       fwrite(outbuf,1,256,fout);
  85.   }
  86.   fclose(fin);
  87.   fclose(fout);
  88.  }
  89.  
  90.  get_lines_arg(s,n)
  91.  char s[];
  92.  int *n;
  93.  { FILE *f;
  94.    char c;
  95.    if(s[0]=='/') switch(s[1]){
  96.        case 'd':
  97.        case 'D':*n=256;
  98.                 break;
  99.        case 'p':
  100.        case 'P':f=fopen("param.dat","rb");
  101.                 fscanf(f,"%c %d",&c,n);
  102.                 break;
  103.        default :error_exit();
  104.    }
  105.    else if( s[0] >='0' && s[0] <= '9') sscanf(s,"%d",n);
  106.    else error_exit();
  107.  }
  108.  error_exit()
  109.  {printf("bad parameters\n");
  110.   exit();
  111.  }
  112.  change_ext(s1,s2)
  113.  char *s1,*s2;
  114. { int i;
  115.   do{
  116.     *(s2++)=*(s1++);
  117.   }while(*(s2-1)!='.');
  118.   strcpy(s2,"flp");
  119. }
  120.